<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("conn.php");
$db = new DBC();

$productid = "";
$downloadTimes = "";
$flashcode = "";
$name = "";
$url = "";
$version = "";
$size = "";
$imageURL = "";
$type1 = "";
$type2 = "";
$age = "0";
$packid = -1; // 无
if (isset($_GET['flashid'])) {
    $sql = "SELECT * FROM t_product_ios WHERE productid = " . $_GET['flashid'];
    $flashid = $_GET['flashid'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $productid = $data[0]['productid'];
        $downloadTimes = $data[0]['downloadtimes'];
        $flashcode = $data[0]['flashcode'];
        $name = $data[0]['name'];
        $age = $data[0]['age'];
        $url = $data[0]['url'];        
        $version = $data[0]['version'];
        $size = $data[0]['size'];
        $imageURL = $data[0]['imageURL'];
        $type1 = $data[0]['type1'];
        $type2 = $data[0]['type2'];
        $isModify = 1;
        $packid = $data[0]['packid'];
    }
} else {
    $isModify = 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }

            .text{
                height:20px;				
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style>
        <script language="javascript">
            function onchange_age(){
                var obj = document.getElementById("age");
                var age = obj.options[obj.selectedIndex].value;
				
            }
			
			function onSubmitCheck(){
				var flashcode = document.getElementById("flashcode").value;
				var flashname = document.getElementById("flashname").value;
				var type2 = document.getElementsByName("type2[]");
				var version = document.getElementById("version").value;
				var apkurl = document.getElementById("apkurl").value;
				var isok = true;
				var ischecked = false;
				for(var i=0;i<type2.length;i++){
					if(type2[i].checked==true){
						ischecked = true;
						break;
					}
				}
				if(flashcode==""){
					alert("\u8bf7输入编码");
					isok = false;
				}else if(flashname==""){
					alert("\u8bf7输入名称");
					isok = false;	
				}else if(version==""){
					al\u8bf7rt("\u8bf7输入版本");
					isok = false;	
				}else if(apkurl==""){
					al\u8bf7rt("\u8bf7输入应用地址");
					isok = false;															
				}else if(!ischecked){
					alert("\u8bf7至少选择一项能力");
					isok = false;
				}
				if(!isok){
					event.returnValue = false;
				}
			}
        </script>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#age").change(function(){
                    $.get("getPackByAge.php?age=1", function(data){
                        var obj = jQuery.parseJSON(data);                        
                        $('#packselect').children().remove().end();
                        $("#packselect").append('<option value="-1">\u65e0</option>');
                        for(var i=0;i<obj.length;i++){                        
                            var option = "<option value="+obj[i].packid+">"+obj[i].packcode+"-"+obj[i].name+"</option>";
                            $("#packselect").append(option);
                        }
                    });			
                });
            });
        </script>
    </head>

    <body>
        <?php
        if (!isset($flashcode)) {
            $flashcode = "";
        }
        if (!isset($name)) {
            $name = "";
        }
        if (!isset($url)) {
            $url = "";
        }
        if (!isset($imageURL)) {
            $imageURL = "";
        }
        ?>
        <br/>
        <form id="form1" name="form1" method="post" action="fileIOS.action.php" enctype="multipart/form-data">
            <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr>
                    <td height="30" bgcolor="#666666"> ID</td>
                    <td bgcolor="#9999FF"><input name="name2" type="text" size="50" class="disable" value="<?php echo $productid; ?>" disabled="disabled"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">下载次数</td>
                    <td bgcolor="#9999FF"><input name="downloadTimes" type="text" size="50" class="disable" value="<?php echo $downloadTimes; ?>" disabled="disabled" /></td>
                </tr>

                <tr>
                    <td height="30" bgcolor="#666666">编号<input name="flashid" type="hidden" value="<?php echo $flashid; ?>"/><input name="isModify" type="hidden" value="<?php echo $isModify; ?>" /></td>
                    <td bgcolor="#9999FF"><input id="flashcode" name="flashcode" type="text" size="50" class="text" value="<?php echo $flashcode; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666"> 应用名<input name="packid" type="hidden" value="<?php echo $packid; ?>"/></td>
                    <td bgcolor="#9999FF"><input id="flashname" name="name" type="text" size="50" class="text" value="<?php echo $name; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666"> 年龄</td>
                    <td bgcolor="#9999FF">
                        <select name="age" id="age" class="text" onchange="onchange_age()"/>
                        <?php
                        for ($i = 0; $i < 6; $i++) {
                            ?>
                            <option value="<?php echo $i; ?>" <?php if ($age == $i) { ?> selected="selected" <?php } ?>><?php echo $i . "-" . ($i + 1) . "岁"; ?></option>
                        <?php } ?>
                        </select></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">类型</td>
                    <td bgcolor="#9999FF"><input name="type1" type="radio" class="text" <?php if (stristr($type1, '1') || $type1 == "") { ?> checked="checked" <?php } ?> value="1" />动画故事&nbsp;<input name="type1" type="radio" class="text" <?php if (stristr($type1, '2')) { ?> checked="checked" <?php } ?> value="2"/>互动学习&nbsp;<input name="type1" type="radio" class="text" <?php if (stristr($type1, '3')) { ?> checked="checked" <?php } ?> value="3"/>益智游戏</td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">能力</td>
                    <td bgcolor="#9999FF"><input name="type2[]" type="checkbox" class="text" <?php if (stristr($type2, '1')) { ?> checked="checked" <?php } ?> value="1"/>认知&nbsp;<input name="type2[]" type="checkbox" class="text" <?php if (stristr($type2, '2')) { ?> checked="checked" <?php } ?> value="2"/>思维&nbsp;<input name="type2[]" type="checkbox" class="text" <?php if (stristr($type2, '3')) { ?> checked="checked" <?php } ?> value="3"/>语言&nbsp;<input name="type2[]" type="checkbox" class="text" <?php if (stristr($type2, '4')) { ?> checked="checked" <?php } ?> value="4"/>艺术&nbsp;<input name="type2[]" type="checkbox" class="text" <?php if (stristr($type2, '5')) { ?> checked="checked" <?php } ?> value="5"/>行为</td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">版本</td>
                    <td bgcolor="#9999FF"><input id="version" name="version" type="text" size="50" class="text" value="<?php echo $version; ?>"/></td>
                </tr>                			                				
                <tr>
                    <td height="30" bgcolor="#666666">IOS应用地址</td>
                    <td bgcolor="#9999FF"><input id="apkurl" name="url" type="text" size="50" class="text" value="<?php echo $url; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">图标</td>
                    <td bgcolor="#9999FF"><input name="imageURL" type="file" size="50" class="text" value="<?php echo $imageURL; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">所属套</td>
                    <td bgcolor="#9999FF"><select name="packid" id="packselect" class="text"/>
                        <option value="-1">无</option>
                        <?php
                        $sql = "SELECT * FROM t_pack WHERE age = " . $age . " ORDER BY packcode";
                        $packs = $db->fetchData($sql);
                        foreach ($packs as $p) {
                            ?>
                            <option value="<?php echo $p['packid']; ?>" <?php if ($packid == $p['packid']) { ?> selected="selected" <?php } ?>><?php echo $p['packcode'] . "-" . $p["name"]; ?></option>
                        <?php } ?>
                        </select></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;</td>
                    <td bgcolor="#9999FF">
                        <input type="submit" name="Submit" value="提交" onclick="onSubmitCheck()" />                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php

function has($type, $num) {
    if (strpos($type, $num) >= 0) {
        return true;
    }
    return false;
}

include_once 'footer.php';
//} else {
//    header("login.php");
//}
?>
